SD-2440 - fix: toc not loading on paragraphs#2706
Conversation
|
Status: PASS The OOXML field character handling in this PR is spec-compliant. The inline TOC decodes to the standard complex field structure defined in ECMA-376 §17.16.2: All three pieces check out:
The only difference from the block variant is that the runs are returned as a flat array for injection into an existing paragraph rather than being wrapped in |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ac0874bd59
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
…sed-list-of-tablesfigures-toc
…sed-list-of-tablesfigures-toc
caio-pizzol
left a comment
There was a problem hiding this comment.
@chittolinag tested with the original bug file + 13 other Word files. no crashes.
block TOCs decode children twice and the second pass can lose data — fix in the inline comment.
tableOfContentsInline was never triggered during testing, even with the original file. if no file produces it, the wrapping logic alone is the fix and the inline node type can be removed.
| if (!exported) return []; | ||
| return Array.isArray(exported) ? exported : [exported]; | ||
| }); | ||
| const blockContentNodes = isInlineNode ? [] : tocContent.map((n) => exportSchemaToJson({ ...params, node: n })); |
There was a problem hiding this comment.
two things:
- block TOCs decode every child twice — once for
inlineContentNodes(thrown away) and once forblockContentNodes(kept). some decoders modify data as they go, so the second pass sees corrupted input. hyperlinks can get dropped. fix:
| const blockContentNodes = isInlineNode ? [] : tocContent.map((n) => exportSchemaToJson({ ...params, node: n })); | |
| const inlineContentNodes = isInlineNode | |
| ? tocContent.flatMap((n) => { | |
| const exported = exportSchemaToJson({ ...params, node: n }); | |
| if (!exported) return []; | |
| return Array.isArray(exported) ? exported : [exported]; | |
| }) | |
| : []; | |
| const blockContentNodes = isInlineNode ? [] : tocContent.map((n) => exportSchemaToJson({ ...params, node: n })); |
- loaded the original
Template_Test_Report.docxwith debug logs —tableOfContentsInlinewas never produced. the paragraph wrapping at lines 42-49 is what prevents the crash. do you have a file that actually triggers the inline path?
There was a problem hiding this comment.
Great catches. just fixed the 1st issue. I am now checking the 2nd issue you mentioned, it seems like there's also a problem when exporting the file (the opening in Word). I'll fix it.
There was a problem hiding this comment.
Ok I've been trying to fix the export issue for a while now but no luck. I am pretty sure the export issue is unrelated though - after removing the TOC & re-exporting the document, the error persists.
If you agree, I'll file a separate ticket to handle it, but in the mean time I'll make sure to fix the issues you mentioned here in the review.
Co-authored-by: Caio Pizzol <97641911+caio-pizzol@users.noreply.github.com>
…sed-list-of-tablesfigures-toc
…sed TOC (SD-2440)
caiopizzol
left a comment
There was a problem hiding this comment.
@chittolinag fix works, tested with the original file — document loads fine. nice simplification on the latest push.
added a few tests and uploaded the bug file to the test corpus so it's covered going forward.
|
🎉 This PR is included in vscode-ext v1.1.0-next.79 |
|
🎉 This PR is included in @superdoc-dev/react v1.0.0-next.33 The release is available on GitHub release |
|
🎉 This PR is included in esign v2.2.0-next.37 The release is available on GitHub release |
|
🎉 This PR is included in template-builder v1.3.0-next.39 The release is available on GitHub release |
|
🎉 This PR is included in superdoc-cli v0.5.0-next.77 The release is available on GitHub release |
|
🎉 This PR is included in superdoc v1.24.0-next.76 The release is available on GitHub release |
|
🎉 This PR is included in superdoc-sdk v1.3.0-next.78 |
|
🎉 This PR is included in superdoc-sdk v1.4.0 |
|
🎉 This PR is included in superdoc v1.25.0 The release is available on GitHub release |
|
🎉 This PR is included in superdoc-cli v0.6.0 The release is available on GitHub release |
|
🎉 This PR is included in vscode-ext v2.3.0-next.1 |
|
🎉 This PR is included in template-builder v1.5.0-next.1 The release is available on GitHub release |
|
🎉 This PR is included in esign v2.3.0-next.1 The release is available on GitHub release |
Issue
Importing documents where the TOC field sits inline inside a paragraph crashed because the converter always emitted block
tableOfContentsnodes that expect paragraph parents. When that type of document is imported, SuperDoc crashes completely.Solution
Detect when the parent disallows block nodes and encode the TOC within a paragraph block.